<?php
/**
 * Tests for News model
 *
 * PHP version 5
 *
 * @package    TV
 * @subpackage Tests
 * @author     Mike Bevz <mike.bevz@data2people.com>
 * @copyright  2007-2008 (c) Mike Bevz
 * @version    SVN: $Id:  $
 *
 *
 */

/**
 * Includes below
 */
require_once dirname(__FILE__).'/../testsConfig.php';
require_once 'PHPUnit/Framework.php';
require_once 'Zend/Auth/Result.php';

/**
 * Tests for News model
 *
 * PHP version 5
 *
 * @package    TV
 * @subpackage Tests
 * @author     Mike Bevz <mike.bevz@data2people.com>
 * @copyright  2007-2008 (c) Mike Bevz
 * @version    SVN: $Id:  $
 *
 */

class NewsTests extends PHPUnit_Framework_TestCase
{
    /**
     * Model class
     *
     * @var Word
     */
    private $_model;
    
    
    protected function setUp()
    {
        $this->_model = new News();
    }

    protected function tearDown()
    {
      unset($this->_model);
    }
    
    public function testSetGetProperties()
    {
        $title = 'testWord';
        $this->_model->title = $title;
        $this->assertEquals($title, $this->_model->title);
        
        $expected = 'http://testWord.com';
        $this->_model->link = $expected;
        $this->assertEquals($expected, $this->_model->link);
        
        $expected = 'If you are coming from relational database background it may be familiar to you how many-to-many associations are
handled: an additional association table is needed.

In many-to-many relations the relation between the two components is always an aggregate relation and the association
table is owned by both ends. For example in the case of users and groups: when a user is being deleted, the groups
he/she belongs to are not being deleted. However, the associations between this user and the groups he/she belongs
to are instead being deleted. This removes the relation between the user and the groups he/she belonged to, but does
not remove the user nor the groups.';
        $this->_model->description = $expected;
        $this->assertEquals($expected, $this->_model->description);
        
        $expected = '1982-11-24 10:10:10';
        $this->_model->pubdate = $expected;
        $this->assertEquals($expected, $this->_model->pubdate);
        
        $expected = '10002';
        $this->_model->views= $expected;
        $this->assertEquals($expected, $this->_model->views);
        
    }
    
    public function testMany2ManyWords()
    {
        $word = new Word();
        $words = $word->getWordByWord('test0');
        if (count($words)>0) {
            $this->_model->Word[] = $words[0];
        } else {
            $this->_model->Word[]->word = 'test0';
        }
        
        //$this->_model->Word[0]->word = 'test0';
        //$this->_model->Word[]->word = 'test1';
        $this->_model->link          = 'http://unique.link.com';
        
        $this->_model->save();
        
        $this->assertEquals('test0', $this->_model->Word[0]->word);
        
        $this->_model->delete();
    }
    
    public function testAddWordAddsWordToTheNewsItem()
    {
        $this->_model->addWord('test0');
        $this->_model->addWord('test1');
        $this->_model->addWord('test1');
        $this->_model->link          = 'http://unique.link.com';
        $this->_model->save();
        
        $this->assertEquals('test0', $this->_model->Word[0]->word);
        $this->assertEquals('test1', $this->_model->Word[1]->word);
        $this->assertEquals('2', $this->_model->Word->count());
        
        $this->_model->delete();
        
    }
   
      
}